package com.hh.servlet.subject;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hh.dao.SubjectDAO;

/**
 * Servlet implementation class SubjectDetail
 */
@WebServlet("/SubjectDetail")
public class SubjectDetail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SubjectDetail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setHeader("content-type", "text/html;charset=UTF-8");
		String pdbm = request.getParameter("pdbm");
		
		String pdbbm = request.getParameter("pdbbm");
		SubjectDAO dao = new SubjectDAO();
		Map<String,String> checks = dao.getChoosesByPdbm(pdbm);
		JSONObject assess = dao.getAssess(pdbbm);
		JSONArray subjects = dao.getSubjects(pdbbm);
		for(int i=0;i<subjects.size();i++){
			JSONObject obj = subjects.getJSONObject(i);
			String yszbm = checks.get(obj.getString("ysbm"));
			JSONArray chooses = dao.getChooses(obj.getString("ysbm"),yszbm);
			obj.put("chooses", chooses);
		}
		assess.put("subjects", subjects);
		request.setAttribute("assess", assess);
		request.getRequestDispatcher("subject.jsp").forward(request,response); 
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
